home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Compute`s Amiga resource 1.adf / Source / ALC / advtitle.c < prev    next >
C/C++ Source or Header  |  1989-02-07  |  6KB  |  225 lines

  1. /* Advanced Laser Chess title animation */
  2.  
  3. #include "advlaser.h"
  4. #include "advsound.h"
  5.  
  6. /* External variables */
  7. extern struct Screen *screen;  /* From ADVGRAPH.C */
  8. extern struct BitMap primary_bitmap; /* From ADVGRAPH.C */
  9. extern struct BitMap backup_bitmap;
  10. extern struct BitMap *current_bitmap;
  11. extern int bitmap_to_use;      /* From ADVGRAPH.C */
  12. extern struct TextAttr font;
  13.  
  14. /* Local variables */
  15. int xd[TITLEPOINTS], yd[TITLEPOINTS]; /* X and Y directions for all letter points */
  16. int xv[TITLEPOINTS], yv[TITLEPOINTS]; /* X and Y velocities for all letter points */
  17. int xp[TITLEPOINTS], yp[TITLEPOINTS]; /* X and Y positions for all letter points */
  18. short lax[] = {2, 0, 2, 4, 1, 3, -1}; /* Letter A's X & Y point definitions */
  19. short lay[] = {0, 6, 0, 6, 3, 3};     /* (defined as 5 X 7) */
  20. short lcx[] = {0, 4, 0, 0, 0, 4, -1}; /* Letter C's definition */
  21. short lcy[] = {0, 0, 0, 6, 6, 6};
  22. short ldx[] = {0, 3, 4, 4, 0, 3, 0, 0, 3, 4, 3, 4, -1}; /* D */
  23. short ldy[] = {0, 0, 1, 5, 6, 6, 0, 6, 0, 1, 6, 5};
  24. short lex[] = {0, 4, 0, 0, 0, 4, 0, 3, -1}; /* E */
  25. short ley[] = {0, 0, 0, 6, 6, 6, 3, 3};
  26. short lhx[] = {0, 0, 4, 4, 0, 4, -1};       /* H */
  27. short lhy[] = {0, 6, 0, 6, 3, 3};
  28. short llx[] = {0, 0, 0, 4, -1};             /* L */
  29. short lly[] = {0, 6, 6, 6};
  30. short lnx[] = {0, 0, 4, 4, 0, 4, -1};       /* N */
  31. short lny[] = {0, 6, 0, 6, 0, 6};
  32. short lrx[] = {0, 4, 4, 4, 4, 1, 1, 4, 0, 0, -1}; /* R */
  33. short lry[] = {0, 0, 0, 3, 3, 3, 3, 6, 0, 6};
  34. short lsx[] = {0, 4, 0, 0, 0, 4, 4, 4, 0, 4, -1}; /* S */
  35. short lsy[] = {0, 0, 0, 3, 3, 3, 3, 6, 6, 6};
  36. short lvx[] = {0, 2, 2, 4, -1};                   /* V */
  37. short lvy[] = {0, 6, 6, 0};
  38. int xdestpt[] = {15, 54, 93, 132, 171, 210, 249, 288,  /* Upper left x positions */
  39.                  73, 112, 151, 190, 229,              /* of letter "cells" */
  40.                  73, 112, 151, 190, 229};             /* (destinations) */
  41. int ydestpt[] = {22, 22, 22, 22, 22, 22, 22, 22,      /* ADVANCED */
  42.                  74, 74, 74, 74, 74,                  /* LASER    */
  43.                  126, 126, 126, 126, 126};            /* CHESS    */
  44. int addli, addlk;
  45.  
  46.  
  47.  
  48. title()
  49. {
  50.   register int i;
  51.  
  52.   reset_view();
  53.   clear_screen(&primary_bitmap);
  54.   /* Fade all colors FROM the background color, don't modify sound */
  55.   fade_all(FALSE, FALSE);
  56.   title_reset();  /* Reset the title variables and points */
  57.   init_points();  /* Initialize the title letter points */
  58.   set_title_drawing(); /* Initialize drawing parameters for title */
  59.   dequeue_window();
  60.   title_sound(TRUE);
  61.   wait_for_release( !move_points(TRUE) );
  62.   for(i=0; i<TITLEPOINTS; i++)
  63.   {
  64.     xd[i] = SCREENX / 2;
  65.     yd[i] = SCREENY / 2;
  66.   }
  67.   move_points(FALSE);
  68.   title_sound(FALSE);
  69.   clear_screen(&primary_bitmap);
  70.   reset_view();
  71.   /* Fade all colors to background, don't modify sound */
  72.   fade_all(TRUE, FALSE);
  73.   ShowTitle(screen, (long)TRUE);  /* Display screen's title bar */
  74. }
  75.  
  76.  
  77.  
  78. title_reset()
  79. {
  80.   addli = addlk = 0;
  81. }
  82.  
  83.  
  84.  
  85. init_points()  /* Figures out destination coordinates of all letter points */
  86. {
  87.   register int i;
  88.  
  89.   addl(lax, lay);    /* Add letter A to the xd & yd arrays */
  90.   addl(ldx, ldy);    /* Add letter D, etc... */
  91.   addl(lvx, lvy);
  92.   addl(lax, lay);
  93.   addl(lnx, lny);
  94.   addl(lcx, lcy);
  95.   addl(lex, ley);
  96.   addl(ldx, ldy);
  97.   addl(llx, lly);
  98.   addl(lax, lay);
  99.   addl(lsx, lsy);
  100.   addl(lex, ley);
  101.   addl(lrx, lry);
  102.   addl(lcx, lcy);
  103.   addl(lhx, lhy);
  104.   addl(lex, ley);
  105.   addl(lsx, lsy);
  106.   addl(lsx, lsy);
  107.   for(i=0; i<TITLEPOINTS; i++)
  108.   {
  109.     xv[i] = yv[i] = 0;
  110.     xp[i] = SCREENX / 2;
  111.     yp[i] = SCREENY / 2;
  112.   }
  113. }
  114.  
  115.  
  116.  
  117. set_title_drawing()  /* Initialize title drawing parameters */
  118. {
  119.   SetAPen(&screen->RastPort, (long)TITLEPENCOLOR); /* Set line colors */
  120.   SetDrMd(&screen->RastPort, JAM1);         /* Set drawing mode */
  121.   SetDrPt(&screen->RastPort, (long)0xFFFF); /* Solid lines */
  122. }
  123.  
  124.  
  125.  
  126. wait_for_release(done)
  127. register int done;
  128. {
  129.   register struct RastPort *rp;
  130.   register BOOL first = TRUE;
  131.   static struct IntuiText itext =
  132.   {
  133.     (int)TITLEPENCOLOR, 1,    /* FrontPen, BackPen */
  134.     JAM1,    /* Drawing mode */
  135.     0, 0,    /* LeftEdge, TopEdge */
  136.     &font,   /* ITextFont */
  137.     (UBYTE *)NULL, /* Text (filled in below) */
  138.     NULL     /* NextText */
  139.   };
  140.  
  141.  
  142.   if(!done) return;
  143.  
  144.   rp = &screen->RastPort;
  145.   itext.IText = (UBYTE *)"by Mike M. Duppong";
  146.   PrintIText(&screen->RastPort, &itext, 90L, 170L);
  147.   itext.IText = (UBYTE *)"(c) 1989 COMPUTE! Publications, Inc.";
  148.   PrintIText(&screen->RastPort, &itext, 21L, 180L);
  149.   while(!release())
  150.   {
  151.     rnd_title_chord(first);
  152.     first = FALSE;
  153.   }
  154.   SetAPen(rp, TITLEPENCOLOR);
  155. }
  156.  
  157.  
  158.  
  159. move_points(beginning) /* Moves all points in the xd & yd arrays */
  160. register int beginning;
  161. {
  162.   register int i, d, cont;
  163.  
  164.   do
  165.   {
  166.     flip_screens();
  167.     clear_screen(current_bitmap);
  168.     cont = FALSE;
  169.     for(i=0; i<TITLEPOINTS; i++)
  170.     {
  171.       if(xp[i] != xd[i] || yp[i] != yd[i])
  172.       {
  173.         cont = TRUE;
  174.         d = xv[i] + SIGN(xd[i] - xp[i]);
  175.         if(abs(d) < VELLIMIT) xv[i] = d;
  176.         d = yv[i] + SIGN(yd[i] - yp[i]);
  177.         if(abs(d) < VELLIMIT) yv[i] = d;
  178.         xp[i] += xv[i];
  179.         yp[i] += yv[i];
  180.         if(abs(xp[i] - xd[i]) < DIST && abs(yp[i] - yd[i]) < DIST)
  181.         {
  182.           xp[i] += SIGN(xd[i] - xp[i]);
  183.           yp[i] += SIGN(yd[i] - yp[i]);
  184.         }
  185.       }
  186.     }
  187.     if(beginning && cont == TRUE) modify_title_sound(1);
  188.     else if(!beginning && cont == TRUE) modify_title_sound(-1);
  189.     draw_points();
  190.     new_view();
  191.   }while(!release() && cont);
  192.   return(cont);  /* This value tells whether the letters were still moving or not */
  193. }
  194.  
  195.  
  196.  
  197. draw_points()
  198. {
  199.   int i;
  200.  
  201.   for(i=0; i<TITLEPOINTS; i+=2)
  202.   {
  203.     Move(&screen->RastPort, (long)xp[i], (long)yp[i]);
  204.     Draw(&screen->RastPort, (long)xp[i + 1], (long)yp[i + 1]);
  205.   }
  206. }
  207.  
  208.  
  209.  
  210. addl(xsrc, ysrc) /* Adds a letter to the X & Y destination arrays */
  211. short *xsrc, *ysrc;
  212. {
  213.   int j = 0;
  214.  
  215.   while(xsrc[j] != -1)
  216.   {
  217.     xd[addli] = xsrc[j] * 4 + xdestpt[addlk];
  218.     yd[addli] = ysrc[j] * 5 + ydestpt[addlk];
  219.     ++addli; /* Destination point counter */
  220.     ++j; /* Source point counter */
  221.   }
  222.   ++addlk; /* Letter counter */
  223. }
  224.  
  225.